vpath %.S stlib
vpath %.c stlib stlib/src source
vpath %.h stlib stlib/cminc stlib/inc source

DEFS +=  -DUSE_STDPERIPH_DRIVER 
DEFS +=  -DSTM32F10X_LD 
#DEFS +=  -D __GNUC__ 

INCS += -Istlib -Istlib/cminc -Istlib/inc -Isource

OBJS += stlib/startup_stm32f10x_ld.o stlib/system_stm32f10x.o
#OBJS += stlib/src/stm32f30x_rcc.o stlib/src/stm32f30x_gpio.o 
OBJS += Init.o stm32f10x_rcc.o  stm32f10x_gpio.o  stm32f10x_exti.o  misc.o

#OBJS += core_cm3.o
OBJS += main.o

#CFLAGS += -mcpu=cortex-m3 -mthumb -Wall
CFLAGS += -mcpu=cortex-m3 -mthumb -Wall
#CFLAGS += -Os
#CFLAGS += -ffunction-sections -fdata-sections

#LFLAGS += -mcpu=cortex-m3 -mthumb 
LFLAGS += -mcpu=cortex-m3 -mthumb
#LFLAGS += -Wl,--gc-sections

all:main.bin
clean:
	@rm -f $(OBJS) main.bin main.elf
	
main.bin:main.elf
	@arm-none-eabi-objcopy -O binary -S $< $@
	
#arm-none-eabi-gcc --specs=nosys.specs $(OTHER_LINK_OPTIONS)
main.elf:$(OBJS)
	@arm-none-eabi-gcc $(LFLAGS) $^ -Tstlib/flash.ld -o $@ --specs=nosys.specs
	@arm-none-eabi-size $@
	
burn:main.bin
	@st-flash write $< 0x08000000
	
%.o:%.S
	@arm-none-eabi-gcc $(CFLAGS) -c $< -o $@
%.o:%.c
	@arm-none-eabi-gcc $(CFLAGS) $(DEFS) $(INCS) -c $< -o $@
